//
//  WmcSelectWatermarkCell.swift
//  YPWatermarkCamera
//
//  Created by 赵新 on 2022/3/31.
//

import UIKit

class WmcSelectWatermarkCell: WmcBaseCollectionCell {
    // Internal

    override func makeUI() {
        imageView.contentMode = .scaleAspectFill
        imageView.clipsToBounds = true
        imageView.layer.cornerRadius = 5
        titleLabel.textColor = .wmc_grayH2_323233
        titleLabel.font = 14.wmc_font
        titleLabel.textAlignment = .center

        contentView.addSubview(bgView)
        bgView.addSubview(imageView)
        bgView.addSubview(titleLabel)
        bgView.addSubview(selectedImageView)

        addSubview(bgView)
        bgView.addSubview(imageView)
        bgView.addSubview(titleLabel)
        bgView.addSubview(selectedImageView)

        bgView.snp.makeConstraints { make in
            make.left.right.top.bottom.equalToSuperview()
        }

        imageView.snp.makeConstraints { make in
            make.left.top.equalTo(6)
            make.right.equalTo(-6)
            make.height.equalTo(104)
        }

        titleLabel.snp.makeConstraints { make in
            make.bottom.equalTo(-8)
            make.left.equalTo(25)
            make.right.equalTo(-25)
            make.height.equalTo(20)
        }

        selectedImageView.snp.makeConstraints { make in
            make.right.equalTo(-6)
            make.centerY.equalTo(titleLabel)
            make.width.height.equalTo(16)
        }
    }

    func configModel(_ model: WmcSelectWatermarkModel) {
        imageView.kf.setImage(with: URL(string: model.data.tempUrl), placeholder: "image_placeholder".wmc_image)
        titleLabel.text = model.data.name

        if model.isSelected {
            selectedImageView.image = "watermark_selected".wmc_image
            bgView.layer.borderColor = UIColor.wmc_mainTheme.cgColor
            bgView.layer.borderWidth = 1
            bgView.backgroundColor = .wmc_blue_EDF3FE
        } else {
            selectedImageView.image = "watermark_not_selected".wmc_image
            bgView.layer.borderColor = UIColor.clear.cgColor
            bgView.layer.borderWidth = 0
            bgView.backgroundColor = UIColor.clear
        }
    }

    // Private

    private lazy var bgView: UIView = {
        let view = UIView()
        view.layer.cornerRadius = 5
        return view
    }()

    private lazy var selectedImageView: UIImageView = {
        let view = UIImageView(image: "watermark_not_selected".wmc_image)
        view.layer.cornerRadius = 4
        view.layer.masksToBounds = true
        return view
    }()
}
